using System;
using System.Runtime.InteropServices;


namespace Installer
{

    public class ApiCopyFile
    {
        private const int FO_COPY = 0x0002;
        private const int FOF_ALLOWUNDO = 0x00044;
        // 0x0010对所有显示的对话框作出响应。
        private const int FOF_NOCONFIRMATION = 0x0010; 
        //  
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 0)]
        public struct SHFILEOPSTRUCT
        {
            public IntPtr hwnd;
            [MarshalAs(UnmanagedType.U4)]
            public int wFunc;
            public string pFrom;
            public string pTo;
            public short fFlags;
            [MarshalAs(UnmanagedType.Bool)]
            public bool fAnyOperationsAborted;
            public IntPtr hNameMappings;
            public string lpszProgressTitle;
        }
        [DllImport("shell32.dll", CharSet = CharSet.Auto)]
        static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);
        public static bool DoCopy(string strSource, string strTarget)
        {
            SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT();
            fileop.wFunc = FO_COPY;
            fileop.pFrom = strSource;
            fileop.lpszProgressTitle = "复制文件";
            fileop.pTo = strTarget;
            //fileop.fFlags = FOF_ALLOWUNDO;  
            fileop.fFlags = FOF_NOCONFIRMATION;

            return SHFileOperation(ref fileop) == 0;
        }
    }
}
